#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
int n,m;
const int N=1e5+50;
int dp[N];
int w[505],v[505];
int main(void){
    while(~scanf("%d%d",&n,&m)){
        memset(w,0,sizeof(w));
        memset(v,0,sizeof(v));
        for(int i=1;i<=n;i++){
            scanf("%d%d",&w[i],&v[i]);
        }
        //一维数组的话要逆推
        for(int i=1;i<=n;i++){
            for(int j=m;j>=w[i];j--){
                dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
            }
        }       
        printf("%d\n",dp[m]);
    }
    return 0;
}